package com.gumanx;

import net.minecraft.block.Block;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.World;

public class ItemInstantHouse extends Item {

	public ItemInstantHouse(int par1) {
		super(par1);
		this.setCreativeTab(CreativeTabs.tabTools);
	}
	
	public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)
	{
		if (!par2World.isRemote)
        {
                par3EntityPlayer.posY++;
                MovingObjectPosition coord = par3EntityPlayer.rayTrace(500, 1);
                if (coord != null)
                {
                        int height = 4;
                        int length = 10;
                        int depth = 10;
                        coord.blockX -= length/2;
                        coord.blockZ -= depth/2;
                       
                       
                        for (int j = 0; j < length; j ++)
                        {
                                for (int k = 0; k < depth; k ++)
                                {
                                        par2World.setBlock((int)coord.blockX+j, (int)coord.blockY,(int) coord.blockZ+k, Block.cobblestone.blockID);
                                }
                        }
                        coord.blockY++;
                        for (int i = 0;i < height;i++)
                        {
                                for (int j = 0; j < length; j ++)
                                {
                                        par2World.setBlock((int)coord.blockX++, (int)coord.blockY,(int) coord.blockZ, Block.planks.blockID);
                                       
                                }
                                for (int k = 0; k < depth; k ++)
                                {
                                        par2World.setBlock((int)coord.blockX, (int)coord.blockY,(int) coord.blockZ++, Block.planks.blockID);
                                       
                                }
                                for (int l = 0; l < length; l ++)
                                {
                                        par2World.setBlock((int)coord.blockX--, (int)coord.blockY,(int) coord.blockZ, Block.planks.blockID);
                                       
                                }
                                for (int m = 0; m< depth; m ++)
                                {
                                        par2World.setBlock((int)coord.blockX, (int)coord.blockY,(int) coord.blockZ--, Block.planks.blockID);
                                       
                                }
                                par2World.setBlock((int)coord.blockX, (int)coord.blockY,(int) coord.blockZ, Block.wood.blockID);
                                par2World.setBlock((int)coord.blockX+10, (int)coord.blockY,(int) coord.blockZ+10, Block.wood.blockID);
                                par2World.setBlock((int)coord.blockX+10, (int)coord.blockY,(int) coord.blockZ, Block.wood.blockID);
                                par2World.setBlock((int)coord.blockX, (int)coord.blockY,(int) coord.blockZ+10, Block.wood.blockID);
                                par2World.setBlock((int)coord.blockX+5, (int)coord.blockY,(int) coord.blockZ, Block.wood.blockID);
                                par2World.setBlock((int)coord.blockX+5, (int)coord.blockY,(int) coord.blockZ, Block.wood.blockID);
                                par2World.setBlock((int)coord.blockX+5, (int)coord.blockY,(int) coord.blockZ+10, Block.wood.blockID);
                                par2World.setBlock((int)coord.blockX+10, (int)coord.blockY,(int) coord.blockZ+5, Block.wood.blockID);
                                par2World.setBlock((int)coord.blockX, (int)coord.blockY,(int) coord.blockZ+5, Block.wood.blockID);
                                
                                coord.blockY++;
                        }
                        coord.blockY--;
                        for (int j = 0; j < length; j ++)
                        {
                                for (int k = 0; k < depth; k ++)
                                {
                                        par2World.setBlock((int)coord.blockX+j, (int)coord.blockY,(int) coord.blockZ+k, Block.glass.blockID);
                                }
                        }
                        par2World.setBlock((int)coord.blockX+9, (int)coord.blockY-3,(int) coord.blockZ+9, Block.workbench.blockID);
                        par2World.setBlock((int)coord.blockX+9, (int)coord.blockY-3,(int) coord.blockZ+8, Block.furnaceBurning.blockID);
                        par2World.setBlock((int)coord.blockX+9, (int)coord.blockY-2,(int) coord.blockZ+9, Block.furnaceBurning.blockID);
                        par2World.setBlock((int)coord.blockX+9, (int)coord.blockY-2,(int) coord.blockZ+8, Block.furnaceBurning.blockID);
                        par2World.setBlock((int)coord.blockX+4, (int)coord.blockY-3,(int) coord.blockZ+1, Block.chest.blockID);
                        par2World.setBlock((int)coord.blockX+5, (int)coord.blockY-3,(int) coord.blockZ+1, Block.chest.blockID);
                       
                        par2World.setBlock((int)coord.blockX+9, (int)coord.blockY,(int) coord.blockZ, Block.planks.blockID);
                        par2World.setBlock((int)coord.blockX+8, (int)coord.blockY,(int) coord.blockZ, Block.planks.blockID);
                        par2World.setBlock((int)coord.blockX+7, (int)coord.blockY,(int) coord.blockZ, Block.planks.blockID);
                        par2World.setBlock((int)coord.blockX+6, (int)coord.blockY,(int) coord.blockZ, Block.planks.blockID);
                        par2World.setBlock((int)coord.blockX+5, (int)coord.blockY,(int) coord.blockZ, Block.wood.blockID);
                        par2World.setBlock((int)coord.blockX+4, (int)coord.blockY,(int) coord.blockZ, Block.planks.blockID);
                        par2World.setBlock((int)coord.blockX+3, (int)coord.blockY,(int) coord.blockZ, Block.planks.blockID);
                        par2World.setBlock((int)coord.blockX+2, (int)coord.blockY,(int) coord.blockZ, Block.planks.blockID);
                        par2World.setBlock((int)coord.blockX+1, (int)coord.blockY,(int) coord.blockZ, Block.planks.blockID);
                        par2World.setBlock((int)coord.blockX, (int)coord.blockY,(int) coord.blockZ, Block.wood.blockID);
                        par2World.setBlock((int)coord.blockX, (int)coord.blockY,(int) coord.blockZ+9, Block.planks.blockID);
                        par2World.setBlock((int)coord.blockX, (int)coord.blockY,(int) coord.blockZ+8, Block.planks.blockID);
                        par2World.setBlock((int)coord.blockX, (int)coord.blockY,(int) coord.blockZ+7, Block.planks.blockID);
                        par2World.setBlock((int)coord.blockX, (int)coord.blockY,(int) coord.blockZ+6, Block.planks.blockID);
                        par2World.setBlock((int)coord.blockX, (int)coord.blockY,(int) coord.blockZ+5, Block.wood.blockID);
                        par2World.setBlock((int)coord.blockX, (int)coord.blockY,(int) coord.blockZ+4, Block.planks.blockID);
                        par2World.setBlock((int)coord.blockX, (int)coord.blockY,(int) coord.blockZ+3, Block.planks.blockID);
                        par2World.setBlock((int)coord.blockX, (int)coord.blockY,(int) coord.blockZ+2, Block.planks.blockID);
                        par2World.setBlock((int)coord.blockX, (int)coord.blockY,(int) coord.blockZ+1, Block.planks.blockID);
                       
                        par2World.setBlock((int)coord.blockX+10, (int)coord.blockY-4,(int) coord.blockZ, Block.cobblestone.blockID);
                        par2World.setBlock((int)coord.blockX+9, (int)coord.blockY-4,(int) coord.blockZ, Block.cobblestone.blockID);
                        par2World.setBlock((int)coord.blockX+8, (int)coord.blockY-4,(int) coord.blockZ, Block.cobblestone.blockID);
                        par2World.setBlock((int)coord.blockX+7, (int)coord.blockY-4,(int) coord.blockZ, Block.cobblestone.blockID);
                        par2World.setBlock((int)coord.blockX+6, (int)coord.blockY-4,(int) coord.blockZ, Block.cobblestone.blockID);
                        par2World.setBlock((int)coord.blockX+5, (int)coord.blockY-4,(int) coord.blockZ, Block.cobblestone.blockID);
                        par2World.setBlock((int)coord.blockX+4, (int)coord.blockY-4,(int) coord.blockZ, Block.cobblestone.blockID);
                        par2World.setBlock((int)coord.blockX+3, (int)coord.blockY-4,(int) coord.blockZ, Block.cobblestone.blockID);
                        par2World.setBlock((int)coord.blockX+2, (int)coord.blockY-4,(int) coord.blockZ, Block.cobblestone.blockID);
                        par2World.setBlock((int)coord.blockX+1, (int)coord.blockY-4,(int) coord.blockZ, Block.cobblestone.blockID);
                        par2World.setBlock((int)coord.blockX, (int)coord.blockY-4,(int) coord.blockZ, Block.cobblestone.blockID);
                        par2World.setBlock((int)coord.blockX, (int)coord.blockY-4,(int) coord.blockZ+10, Block.cobblestone.blockID);
                        par2World.setBlock((int)coord.blockX, (int)coord.blockY-4,(int) coord.blockZ+9, Block.cobblestone.blockID);
                        par2World.setBlock((int)coord.blockX, (int)coord.blockY-4,(int) coord.blockZ+8, Block.cobblestone.blockID);
                        par2World.setBlock((int)coord.blockX, (int)coord.blockY-4,(int) coord.blockZ+7, Block.cobblestone.blockID);
                        par2World.setBlock((int)coord.blockX, (int)coord.blockY-4,(int) coord.blockZ+6, Block.cobblestone.blockID);
                        par2World.setBlock((int)coord.blockX, (int)coord.blockY-4,(int) coord.blockZ+5, Block.cobblestone.blockID);
                        par2World.setBlock((int)coord.blockX, (int)coord.blockY-4,(int) coord.blockZ+4, Block.cobblestone.blockID);
                        par2World.setBlock((int)coord.blockX, (int)coord.blockY-4,(int) coord.blockZ+3, Block.cobblestone.blockID);
                        par2World.setBlock((int)coord.blockX, (int)coord.blockY-4,(int) coord.blockZ+2, Block.cobblestone.blockID);
                        par2World.setBlock((int)coord.blockX, (int)coord.blockY-4,(int) coord.blockZ+1, Block.cobblestone.blockID);
                       
                        par2World.setBlock((int)coord.blockX+10, (int)coord.blockY-4,(int) coord.blockZ+10, Block.cobblestone.blockID);
                        par2World.setBlock((int)coord.blockX+9, (int)coord.blockY-4,(int) coord.blockZ+10, Block.cobblestone.blockID);
                        par2World.setBlock((int)coord.blockX+8, (int)coord.blockY-4,(int) coord.blockZ+10, Block.cobblestone.blockID);
                        par2World.setBlock((int)coord.blockX+7, (int)coord.blockY-4,(int) coord.blockZ+10, Block.cobblestone.blockID);
                        par2World.setBlock((int)coord.blockX+6, (int)coord.blockY-4,(int) coord.blockZ+10, Block.cobblestone.blockID);
                        par2World.setBlock((int)coord.blockX+5, (int)coord.blockY-4,(int) coord.blockZ+10, Block.cobblestone.blockID);
                        par2World.setBlock((int)coord.blockX+4, (int)coord.blockY-4,(int) coord.blockZ+10, Block.cobblestone.blockID);
                        par2World.setBlock((int)coord.blockX+3, (int)coord.blockY-4,(int) coord.blockZ+10, Block.cobblestone.blockID);
                        par2World.setBlock((int)coord.blockX+2, (int)coord.blockY-4,(int) coord.blockZ+10, Block.cobblestone.blockID);
                        par2World.setBlock((int)coord.blockX+1, (int)coord.blockY-4,(int) coord.blockZ+10, Block.cobblestone.blockID);
                        par2World.setBlock((int)coord.blockX, (int)coord.blockY-4,(int) coord.blockZ, Block.cobblestone.blockID);
                        par2World.setBlock((int)coord.blockX+10, (int)coord.blockY-4,(int) coord.blockZ+9, Block.cobblestone.blockID);
                        par2World.setBlock((int)coord.blockX+10, (int)coord.blockY-4,(int) coord.blockZ+10, Block.cobblestone.blockID);
                        par2World.setBlock((int)coord.blockX+10, (int)coord.blockY-4,(int) coord.blockZ+8, Block.cobblestone.blockID);
                        par2World.setBlock((int)coord.blockX+10, (int)coord.blockY-4,(int) coord.blockZ+7, Block.cobblestone.blockID);
                        par2World.setBlock((int)coord.blockX+10, (int)coord.blockY-4,(int) coord.blockZ+6, Block.cobblestone.blockID);
                        par2World.setBlock((int)coord.blockX+10, (int)coord.blockY-4,(int) coord.blockZ+5, Block.cobblestone.blockID);
                        par2World.setBlock((int)coord.blockX+10, (int)coord.blockY-4,(int) coord.blockZ+4, Block.cobblestone.blockID);
                        par2World.setBlock((int)coord.blockX+10, (int)coord.blockY-4,(int) coord.blockZ+3, Block.cobblestone.blockID);
                        par2World.setBlock((int)coord.blockX+10, (int)coord.blockY-4,(int) coord.blockZ+2, Block.cobblestone.blockID);
                        par2World.setBlock((int)coord.blockX+10, (int)coord.blockY-4,(int) coord.blockZ+1, Block.cobblestone.blockID);
                       
                        par2World.setBlock((int)coord.blockX, (int)coord.blockY-3,(int) coord.blockZ+7, Block.sapling.blockID);
                        par2World.setBlock((int)coord.blockX, (int)coord.blockY-2,(int) coord.blockZ+7, Block.sapling.blockID);
                       
                        par2World.setBlock((int)coord.blockX+1, (int)coord.blockY-2,(int) coord.blockZ+7, Block.torchWood.blockID);
                        par2World.setBlock((int)coord.blockX+1, (int)coord.blockY-2,(int) coord.blockZ+6, Block.torchWood.blockID);
                        par2World.setBlock((int)coord.blockX+1, (int)coord.blockY-2,(int) coord.blockZ+3, Block.torchWood.blockID);
                        par2World.setBlock((int)coord.blockX+1, (int)coord.blockY-2,(int) coord.blockZ+2, Block.torchWood.blockID);
                        par2World.setBlock((int)coord.blockX+7, (int)coord.blockY-2,(int) coord.blockZ+1, Block.torchWood.blockID);
                        par2World.setBlock((int)coord.blockX+6, (int)coord.blockY-2,(int) coord.blockZ+1, Block.torchWood.blockID);
                        par2World.setBlock((int)coord.blockX+3, (int)coord.blockY-2,(int) coord.blockZ+1, Block.torchWood.blockID);
                        par2World.setBlock((int)coord.blockX+2, (int)coord.blockY-2,(int) coord.blockZ+1, Block.torchWood.blockID);
                       
                        par2World.setBlock((int)coord.blockX+9, (int)coord.blockY-2,(int) coord.blockZ+7, Block.torchWood.blockID);
                        par2World.setBlock((int)coord.blockX+9, (int)coord.blockY-2,(int) coord.blockZ+6, Block.torchWood.blockID);
                        par2World.setBlock((int)coord.blockX+9, (int)coord.blockY-2,(int) coord.blockZ+3, Block.torchWood.blockID);
                        par2World.setBlock((int)coord.blockX+9, (int)coord.blockY-2,(int) coord.blockZ+2, Block.torchWood.blockID);
                        par2World.setBlock((int)coord.blockX+7, (int)coord.blockY-2,(int) coord.blockZ+9, Block.torchWood.blockID);
                        par2World.setBlock((int)coord.blockX+6, (int)coord.blockY-2,(int) coord.blockZ+9, Block.torchWood.blockID);
                        par2World.setBlock((int)coord.blockX+3, (int)coord.blockY-2,(int) coord.blockZ+9, Block.torchWood.blockID);
                        par2World.setBlock((int)coord.blockX+2, (int)coord.blockY-2,(int) coord.blockZ+9, Block.torchWood.blockID);
                       
                        par2World.setBlock((int)coord.blockX+9, (int)coord.blockY-3,(int) coord.blockZ+1, Block.stairsWoodOak.blockID);
                        par2World.setBlock((int)coord.blockX+9, (int)coord.blockY-3,(int) coord.blockZ+2, Block.stairsWoodOak.blockID);
                        par2World.setBlock((int)coord.blockX+9, (int)coord.blockY-3,(int) coord.blockZ+3, Block.stairsWoodOak.blockID);
                        par2World.setBlock((int)coord.blockX+7, (int)coord.blockY-3,(int) coord.blockZ+2, Block.planks.blockID);
                }
                par3EntityPlayer.posY--;
        }
		return par1ItemStack;
	}
	
	public void registerIcons(IconRegister iconReg)
	{
		itemIcon = iconReg.registerIcon("gumanx:instantHouse");
	}

}
